package com.goods.controller.business;

import com.goods.business.service.ConsumerService;
import com.goods.common.model.business.Consumer;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 物资去处页面接口
 */
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;

    //加载物资去处列表
    @GetMapping("/findConsumerList")
    public ResponseBean findAll(@RequestParam Map<String,Object> map){
        PageVO<ConsumerVO> pageVO = consumerService.findAll(map);
        return ResponseBean.success(pageVO);
    }

    //添加物资去处列表
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ConsumerVO consumerVO){
        consumerService.add(consumerVO);
        return ResponseBean.success();
    }

    //打开编辑页面,并且回显
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ConsumerVO consumerVO = consumerService.edit(id);
        return ResponseBean.success(consumerVO);
    }

    //更新用户
    @PutMapping("/update/{id}")
    public ResponseBean update(@RequestBody ConsumerVO consumerVO){
        consumerService.update(consumerVO);
        return ResponseBean.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        consumerService.delete(id);
        return ResponseBean.success();
    }

    //加载去向数据
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<ConsumerVO> listVO = consumerService.fdAll();
        return ResponseBean.success(listVO);
    }

}
